package com.alittle.core;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;



public abstract class ALBaseFragment extends Fragment {

    protected Context getSelfContext() {
        return getActivity();
    }

    public void onSelfBackPressed() {
        getActivity().onBackPressed();
    }

    @SuppressWarnings("unchecked")
    protected <T extends View> T findById(int resId) {
        return (T) getView().findViewById(resId);
    }

    @SuppressWarnings("unchecked")
    protected <T extends View> T findById(View view, int resId) {
        return (T) view.findViewById(resId);
    }

    //############# lift circle #############

    @Deprecated
    protected LittleApp getSelfApplication() {
        return (LittleApp) getActivity().getApplication();
    }

    protected ALBaseActivity getSelfActivity() {
        return (ALBaseActivity) getActivity();
    }

    ///////////////////////////////////

//    /**
//     * 如果Fragment本身就含有一个 Toolbar,就不用去干涉容器Activity的菜单
//     */
//    private PseudoToolbar pseudoToolbar;
//
//    public void setSelfTitle(String title) {
//        if (!isAdded()) {
//            return;
//        }
//        if (pseudoToolbar == null) {
//            getSelfActivity().setSelfTitle(title);
//        } else {
//            pseudoToolbar.setTitle(title);
//        }
//    }

    @LayoutRes
    protected int getSelfLayoutViewId() {
        return 0;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        int layoutResId = getSelfLayoutViewId();
        return inflater.inflate(layoutResId, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);
    }




}
